package com.bree.erp.report.birt;

import java.io.InputStream;

import org.apache.log4j.Logger;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;

import com.bree.erp.report.birt.param.PurchaseOrderFormParam;
import com.bree.erp.report.entity.po.PurchaseOrderDataSet;

public class PurchaseOrderForm extends AbstractReport {

	private static Logger LOG = Logger.getLogger(PurchaseOrderForm.class);
			
	private PurchaseOrderFormParam param;
	private PurchaseOrderDataSet purchaseOrderDataSet;

	public PurchaseOrderForm(PurchaseOrderFormParam param) {
		this.param = param;
	}

	@Override
	protected InputStream getReportDesign() {
		final String resourceName = this.getReportName() + ".rptdesign";
		InputStream is = PurchaseOrderForm.class.getResourceAsStream(resourceName);
		
		LOG.debug(resourceName + " @ " + is);
		
		return is;
	}

	@Override
	protected String getReportName() {
		return this.getClass().getSimpleName();
	}

	@Override
	protected Object getDataSet() {
		LOG.debug("Setting Order DataSet");
		return purchaseOrderDataSet;
	}

	@Override
	protected void setParameterValues(IRunAndRenderTask task) {
		LOG.debug("Setting parameter values");
		task.setParameterValue("warehouseAddress", param.getWarehouseAddress());
		task.setParameterValue("supplierAddress", param.getSupplierAddress());

		task.setParameterValue("purchaseDate", param.getPurchaseDate());
		task.setParameterValue("poNumber", param.getPoNumber());
		task.setParameterValue("purchaser", param.getPurchaser());
		task.setParameterValue("dueDate", param.getDueDate());
		task.setParameterValue("terms", param.getTerms());
		task.setParameterValue("totalAmount", param.getTotalAmount());
		task.setParameterValue("remarks", param.getRemarks());
		task.setParameterValue("approver", param.getApprover());
		task.setParameterValue("prNumber", param.getPrNumber());
	}

	/**
	 * @return the purchaseOrderDataSet
	 */
	public PurchaseOrderDataSet getPurchaseOrderDataSet() {
		return purchaseOrderDataSet;
	}

	/**
	 * @param purchaseOrderDataSet the purchaseOrderDataSet to set
	 */
	public void setPurchaseOrderDataSet(PurchaseOrderDataSet purchaseOrderDataSet) {
		this.purchaseOrderDataSet = purchaseOrderDataSet;
	}

}
